#include"Heap.h"

void test1()
{
	int arr[] = { 10,12,23,14,25,6,17,28,9 };
	HP hp;
	HeapInit(&hp);
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		HeapPush(&hp, arr[i]);
	}
	HeapPrint(&hp);
	HeapDestroy(&hp);

}
void test2()
{
	int arr[] = { 10,12,23,14,25,6,17,28,9 };
	HP hp;
	HeapInit(&hp);
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		HeapPush(&hp, arr[i]);
	}
	while (!HeapEmpty(&hp))
	{
		printf("%d ", HeapTop(&hp));
		HeapPop(&hp);
	}
}
//void HeapSort(int* a, int n)
//{
//	HP hp;
//	HeapInit(&hp);
//	int i = 0;
//	for (i = 0; i < n; i++)
//	{
//		HeapPush(&hp, a[i]);
//	}
//	for (i = 0; i < n; i++)
//	{
//		a[i] = HeapTop(&hp);
//		HeapPop(&hp);
//	}
//	HeapDestroy(&hp);
//}
void HeapSort(int* a, int n)
{
	int i = 0;
	int j = 0;
	for (i = 1; i < n; i++)
	{
		AdjustUp_big(a, i);
	}
	printf("\n");

	for (j = 0; j < n; j++)
	{
		printf("%d ", a[j]);
	}
	printf("\n");
	j = 0;
	while (j + 1 < n)
	{
		Swap(&a[0], &a[n - 1 - j]);
		AdjustDown(a, n - j - 1, 0);
		j++;
	}
	
}
void test3()
{
	int arr[] = { 10,12,23,14,25,6,17,28,9 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	HeapSort(arr, sz);
	printf("\n");
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}

int main()
{
	//test2();
	//test1();
	test3();
	return 0;
}


